<template>
	<view>
		<view class="top_scroll">
			<scroll-view enable-flex scroll-x class="scroll_box">
				<view class="scroll_item " v-for="item in scrollList" :key="item.id" @click="clickNav(item.id)">
					<view class="item" :class="item.id==navId?'active':''">{{item.name}}</view>
				</view>
			</scroll-view>
		</view>

		<view class="box" v-for="(item,index) in list" :key="index">
			<view class="info" @click="toPostComments(item)">
				<image :src="item.img?item.img.split(',')[0]:''" class="info_left"></image>
				<view class="info_right">
					<view class="title_box">
						<view class="title">{{item.course_name}}</view>
						<!-- 0待开课1待上课2待评价3已完结4进行中 -->
						<view class="status">{{pay_status[item.class_status]}}</view>
					</view>
					<view class="time_box">
						<view class="tag">报名截止时间</view>
						<view class="time">{{dateFormat(item.sign_end_time)}}</view>
						
					</view>
					<view class="teacher">共{{item.class_hour}}课节</view>
					<view class="teacher">
						<view>老师:{{item.teacher_name}}</view>
					</view>
					<!-- <view class="student">
						学生:
						<view class="studentitem">
							<view v-for="(s,sinex) in item.family" :key="sindex">
								{{s.name}}
							</view>
						</view>
					</view> -->
				</view>
			</view>
			<view class="btns"  v-if="item.class_status==4||item.class_status==2" >
				<!-- //0待开课1待上课2待评价3已完结4进行中 -->
				<!-- <view class="btn_box"  v-if="item.pay_status==1">
					<view class="btn1" @click="toApplyRefund">申请退款</view>
					<view class="btn2" :style="{'opacity':item.is_can_hx==0?0.5:''}" @click="openHxm(item)">核销二维码</view>
				</view> -->
				<!-- <view class="btn3" v-if="item.class_status==1" @click.stop="toscan(item)">扫码核销</view> -->
				<view class="btn3" v-if="item.class_status==2" @click.stop="toPostComments(item)">待评价</view>
				<view class="btn3"  v-if="item.class_status==4" @click.stop="open(item)">确认结课</view>
			</view>
		</view>
		<kong v-if="list.length==0"></kong>

		<!-- 确认结课 -->
		<uni-popup ref="popup" background-color="#fff">
			<view class="popup_box">
				<view class="title_box">
					<!-- <text class="zw"></text> -->
					<view>您确认要完结这门课程吗？</view>
					<!-- <image src="../../static/off.png" @click="offHxm"></image> -->
				</view>
				<!-- <view class="popup_hxm">
					<image class="hxm" :src="qrcode"></image>
				</view> -->
				<view class="btns">
					<view class="btn1" @click="offHxm">取消</view>
					<view class="btn2" @click="sureclass()">确认结课</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import kong from '../../components/kong.vue'
	export default {
		components:{
			kong
		},
		data() {
			return {
				scrollList: [{
						name: "全部",
						id: ''
					},
					{
						name: "待上课",
						id: 1
					},
					{
						name: "进行中",
						id: 4
					},
					
					{
						name: "已完结",
						id: 3
					},
					{
						name: "待评价",
						id: 2
					},
				],
				pay_status:['待开课','待上课','待评价','已完结','进行中'],//0待开课1待上课2待评价3已完结4进行中
				navId: '',
				list:[],
				page:1,
				is_data:true,
				qrcode:'',//核销码
				sureinfo:{},
			}
		},
		onLoad(option) {
			this.getlist(option.id)
		},
		onshow(){
			// this.getlist()
		},
		onReachBottom() {
			this.is_data&&this.getlist(this.navId)
		},
		methods: {
			// // 跳转课程详情
			// toCourseDetails(item){
			// 	uni.navigateTo({
			// 		url:'/pagemy/courseinfo/courseinfo?id='+item.id
			// 	})
			// },
			//跳转评价
			toPostComments(item){
					uni.navigateTo({
						url:'/pagemy/courseinfo/courseinfo?id='+item.id
					})
				},
			open(item){
				 this.$refs.popup.open('center')
				 this.sureinfo = item
			},
			// 确认结课
			sureclass(){
				this.$http({
					url:'/api/Course/confirm',
					data:{
						teacher_course_id:this.sureinfo.id
					}
				}).then(res=>{
					this.offHxm()
					this.getlist(this.navId||'')
					uni.showToast({
						title:res.msg,
						icon:'none'
					})
				})
			},
			// 扫码核销
			toscan(item) {
				// 只允许通过相机扫码
				let that = this
				uni.scanCode({
					onlyFromCamera: true,
					success: function(res) {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
						that.$http({
							url: 'api/course/course_hx',
							data: {
								order_id: res.result
							}
						}).then(res => {
							uni.showToast({
								title:res.msg,
								icon:'none',
								duration:3000
							})
						})
					}
				});
			},
			// 关闭核销码
			offHxm() {
				this.$refs.popup.close()
			},
			// 点击上方导航栏
			clickNav(id) {
				this.list=[]
				this.page=1
				this.navId = id
				this.getlist(id)
			},
			getlist(id){
				uni.showLoading({
					title:'加载中……'
				})
				this.$http({
					url:'/api/course/teacher_order_list',
					data:{
						class_status:id||'',//0待开课1待上课2待评价3已完结4进行中
						page:this.page,
						limit:20,
					}
				}).then(res=>{
					uni.hideLoading()
					if(res.data.length){
						this.list.push(...res.data)
						this.page++
						return
					}
					this.is_data = false
				})
			},
			dateFormat: function(value) {
			                var date = new Date(value*1000); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
			                var year = date.getFullYear();
			                var month = ("0" + (date.getMonth() + 1)).slice(-2);
			                var sdate = ("0" + date.getDate()).slice(-2);
			                var hour = ("0" + date.getHours()).slice(-2);
			                var minute = ("0" + date.getMinutes()).slice(-2);
			                var second = ("0" + date.getSeconds()).slice(-2);
			                // 拼接
			                var result = year + "年" + month + "月" + sdate + "日" + hour + ":" + minute //+ ":" + second;
			                // 返回
			                return result;
			            },
		}
	}
</script>

<style lang="scss" scoped>
	// 顶部导航栏
	.top_scroll {
		width: 750rpx;
		height: 86rpx;
		background: #FFFFFF;
		border-radius: 0rpx 0rpx 10rpx 10rpx;
		display: flex;
		margin-bottom: 20rpx;

		.scroll_box {
			width: 100%;
			display: flex;
			justify-content: space-between;

			.scroll_item {
				width: calc(100% / 5);
				height: 100%;
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 32rpx;
				font-family: Source Han Sans CN-Medium, Source Han Sans CN;
				font-weight: 500;
				color: #222222;

				.item {
					height: 100%;
					display: flex;
					justify-content: center;
					align-items: center;
				}

				.active {
					color: #FF6178;
					background: linear-gradient(#fff 0%, #fff 95%, #FFE6EB 95%, #FF8A9B 100%);
				}
			}
		}
	}

	// 
	.box {
		width: 750rpx;
		background: #FFFFFF;
		border-radius: 10rpx;
		padding: 36rpx 30rpx 0 30rpx;
		box-sizing: border-box;
		margin-bottom: 24rpx;

		.info {
			display: flex;
			justify-content: space-between;
			gap: 0 26rpx;
			padding-bottom: 30rpx;

			.info_left {
				width: 160rpx;
				height: 160rpx;
				background: #FFFFFF;
				border-radius: 6rpx;
				flex-shrink: 0;
			}

			.info_right {
				width: 100%;
				display: flex;
				flex-direction: column;

				.title_box {
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-bottom: 30rpx;

					.title {
						font-size: 36rpx;
						font-family: Source Han Sans CN-Medium, Source Han Sans CN;
						font-weight: 500;
						color: #222222;
						line-height: 1em;
					}

					.status {
						font-size: 28rpx;
						font-family: Source Han Sans CN-Medium, Source Han Sans CN;
						font-weight: 500;
						color: #FF8A9B;
					}
				}

				.time_box {
					display: flex;
					align-items: center;
					margin-bottom: 20rpx;
					// justify-content: space-between;

					.tag {
						padding: 6rpx 6rpx 4rpx 6rpx;
						background: linear-gradient(180deg, #FCBB8C 0%, #FF8158 100%);
						font-size: 28rpx;
						font-family: Source Han Sans CN-Medium, Source Han Sans CN;
						font-weight: 500;
						color: #FFFFFF;
						line-height: 1em;
						border-radius: 4rpx 8rpx 8rpx 8rpx;
						margin-right: 18rpx;
					}

					.time {
						font-size: 28rpx;
						font-family: Source Han Sans CN-Regular, Source Han Sans CN;
						font-weight: 400;
						color: #555555;
						line-height: 1em;
						// margin-right: 20rpx;
					}

					.class_hour {
						font-size: 28rpx;
						font-family: Source Han Sans CN-Regular, Source Han Sans CN;
						font-weight: 400;
						color: #555555;
						line-height: 1em;
					}
				}

				.teacher,
				.student {
					font-size: 28rpx;
					font-family: Source Han Sans CN-Medium, Source Han Sans CN;
					font-weight: 500;
					color: #555555;
					line-height: 1em;
					display: flex;
					align-items: center;
					.studentitem{
						display: flex;
						width: 400rpx;
						>view{
							-webkit-line-clamp: 1;
							display: -webkit-box;
							-webkit-box-orient: vertical;
							overflow: hidden;
							text-overflow: ellipsis;
						}
					}
					>view{
						-webkit-line-clamp: 1;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						overflow: hidden;
						text-overflow: ellipsis;
					}
				}

				.teacher {
					margin-bottom: 20rpx;
				}
			}
		}

		.btns {
			width: 690rpx;
			height: 108rpx;
			border-top: 2rpx solid #ECECEC;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.btn_box {
				width: 100%;
				height: 100%;
				display: flex;
				justify-content: space-between;
				align-items: center;
			}

			.btn1 {
				width: 320rpx;
				height: 68rpx;
				border-radius: 36rpx;
				border: 2rpx solid #888888;
				font-size: 32rpx;
				font-family: Source Han Sans CN-Medium, Source Han Sans CN;
				font-weight: 500;
				color: #222222;
				display: flex;
				justify-content: center;
				align-items: center;
			}

			.btn2 {
				width: 320rpx;
				height: 68rpx;
				background: #FF8A9B;
				border-radius: 36rpx;
				font-size: 32rpx;
				font-family: Source Han Sans CN-Medium, Source Han Sans CN;
				font-weight: 500;
				color: #FFFFFF;
				display: flex;
				justify-content: center;
				align-items: center;
			}

			.btn3 {
				width: 690rpx;
				height: 68rpx;
				border-radius: 36rpx;
				// border: 2rpx solid #888888;
				background: #FF8A9B;
				font-size: 32rpx;
				font-family: Source Han Sans CN-Medium, Source Han Sans CN;
				font-weight: 500;
				color: #FFF;
				display: flex;
				justify-content: center;
				align-items: center;
			}
		}
	}

	// 核销码弹框
	.popup_box {
		width: 607rpx;
		// height: 788rpx;
		background: #FFFFFF;
		border-radius: 14rpx;
		position: fixed;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		display: flex;
		flex-direction: column;
		align-items: center;

		.title_box {
			display: flex;
			justify-content: space-between;
			align-items: center;
			// width: 100%;
			height: 128rpx;
			// padding: 0 32rpx;
			// box-sizing: border-box;
			// flex-shrink: 0;
			text-align: center;

			.zw {
				display: block;
				width: 40rpx;
				height: 40rpx;
			}

			image {
				width: 40rpx;
				height: 40rpx;
			}
		}

		.popup_hxm {
			width: calc(100% - 138rpx);
			height: 100%;
			padding-top: 48rpx;
			box-sizing: border-box;
			margin: 0 auto;
			border-top: 2rpx solid #eee;
			display: flex;
			justify-content: center;

			.hxm {
				width: 428rpx;
				height: 428rpx;
			}
		}

		.btns {
			height: 140rpx;
			width: 100%;
			padding: 0 58rpx;
			box-sizing: border-box;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.btn1 {
				width: 226rpx;
				height: 68rpx;
				border-radius: 36rpx;
				border: 2rpx solid #888888;
				font-size: 32rpx;
				font-family: Source Han Sans CN-Medium, Source Han Sans CN;
				font-weight: 500;
				color: #222222;
				display: flex;
				justify-content: center;
				align-items: center;
			}

			.btn2 {
				width: 226rpx;
				height: 68rpx;
				border-radius: 36rpx;
				background: #FF8A9B;
				font-size: 32rpx;
				font-family: Source Han Sans CN-Medium, Source Han Sans CN;
				font-weight: 500;
				color: #FFFFFF;
				display: flex;
				justify-content: center;
				align-items: center;
			}
		}
	}
</style>
